<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>插件</title>
    <script src="../js/vue.js"></script>
</head>
<body>

<div id="app">
    {{message | capitalize}}
    {{name | globalFilter}}

</div>


<script>

    const NotFound = { template: '<p>Page not found</p>' }
    const Home = { template: '<p>home page</p>' }
    const About = { template: '<p>about page</p>' }

    const routes = {
        '/': Home,
        '/about': About
    };

    Vue.filter('globalFilter',function (value) {
        if (!value) return '';
        value = value.toString();
        return value.charAt(0).toUpperCase() + value.slice(1)
    });
    let vm=new Vue({
        el: '#app',
        data: {
            message: 'zhangsan',
            name:'chenglong',
            currentRoute: window.location.pathname

        },
        // 局部注册过滤器
        filters: {
            capitalize: function (value) {
                if (!value) return '';
                value = value.toString();
                return value.charAt(2).toUpperCase() + value.slice(1)
            }
        },
        computed: {
            ViewComponent () {
                return routes[this.currentRoute] || NotFound
            }
        },
        render (h) { return h(this.ViewComponent) }

    })
</script>
</body>
</html>
